package portal.conf.entity;

public class HostEntity extends BaseConf {
	private static int len=8;
	//private static boolean 
	String[] host = new String[len];
	public HostEntity(){}
	public HostEntity(String val){
		setValue(val);
		/*while(val.contains("  "))
			val=val.replace("  ", " ");
		host= val.split(" ");*/
	}
	public int  size(){
		return len;
	}
	public String getAt(int index)throws ArrayIndexOutOfBoundsException{
		if(host.length>=0&& index<host.length-1 )
			return   host[index];
		throw new ArrayIndexOutOfBoundsException();
	}
	public int length(){
		return host.length;
	}
	public String getHostName(){
		if(host.length>=0)
			return host[0];
		return null;
	}
	@Override
	public String toString(){
		String val="";
		if(host[0]==null)
			return val;
		//System.out.println(host.toString());
		for(int i=0;i< this.size();i++ ){
			//System.out.print(host[i]);
			if(host[i]!=null&& host[i].length()>0)
				val+=host[i]+"  \t";
			else
				val+="()   \t";
		}
		//System.out.println(val);
		//val+="\n";
		return val;
	}

	public void setValue(String val){
		val=val.replaceAll("\t", " ");
		while(val.contains("  "))
			val=val.replace("  ", " ");
		host=val.split(" ",8);//暂时针对最后一列为Dispach_Window的处理方案
	}
	@Override
	public String getKey() {
		// TODO Auto-generated method stub
		return getHostName();
	}
}
